package com.cjk.foundation.dao;

import java.util.Date;
import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import com.cjk.foundation.entity.ChannelEntity;
import com.cjk.foundation.enums.ConfStatus;

@Repository
public interface ChannelDao {
	
	@Insert("insert into `channel`(group_id, user_id, status) values(#{groupId}, #{userId}, #{status}) on duplicate key update status = values(status)")
	public void insert(@Param("groupId") Integer groupId, @Param("userId") Integer userId, @Param("status") ConfStatus status);
	
	public List<ChannelEntity> selectListByCondition(@Param("userId") Integer userId, @Param("page") Integer page, @Param("pageSize") Integer pageSize);
	
	public Integer selectCountByCondition(@Param("userId") Integer userId);
	
	@ResultMap("resultMap")
	@Select("select * from `channel` where group_id = #{groupId}")
	public ChannelEntity selectByGroupId(@Param("groupId") Integer groupId);
	
	@Delete("delete from `channel` where group_id = #{groupId}")
	public void deleteByGroupId(@Param("groupId") Integer groupId);
	
	@Update("update `channel` set status = #{status}, last_conf_time = #{lastConfTime} where group_id = #{groupId}")
	public void conf(@Param("status") ConfStatus status, @Param("lastConfTime") Date lastConfTime, @Param("groupId") Integer groupId);
	
}
